<template>
  <div>
    <h1>当前求和为：{{ sum }}</h1>
    <h1>当前求和放大10倍为：{{ bigSum }}</h1>
    <h1>我在{{ school }}学{{ subject }}</h1>
    <select v-model="number">
      <option :value="1">1</option>
      <option :value="2">2</option>
      <option :value="3">3</option>
    </select>
    <button @click="increment(number)">+</button>
    <button @click="decrement">-</button>
    <!--<button @click="ADD(number)">+</button>-->
    <!--<button @click="DEL(number)">-</button>-->
    <!--<button @click="incrementOdd(number)">当前求和为奇数再加</button>-->
    <!--<button @click="incrementWait(number)">等一等再加</button>-->
    <button @click="addOdd(number)">当前求和为奇数再加</button>
    <button @click="addWait(number)">等一等再加</button>
  </div>
</template>

<script>
import {mapGetters, mapState, mapMutations, mapActions} from 'vuex'

export default {
  name: "Count",
  description: '',
  mixins: [],
  components: {},
  props: [],
  data() {
    return {
      number: 1,
    }
  },
  computed: {
    // 靠程序员自己去写计算属性
    /*sum() {
      return this.$store.state.sum
    },
    school(){
      return this.$store.state.school
    },
    subject(){
      return this.$store.state.subject
    }*/

    // 借助mapState生产计算属性，从state中读取数据（对象写法:不可以简写）
    /*...mapState({
      sum: 'sum',
      school: 'school',
      subject: 'subject'
    }),*/

    // (数组写法)
    ...mapState(['sum', 'school', 'subject']),


    /*bigSum() {
      return this.$store.getters.bigSum
    },*/

    // 借助mapState生产计算属性，从state中读取数据（对象写法:不可以简写）
    /* ...mapGetters({
        bigSum:'bigSum'
      }),*/
    // (数组写法)
    ...mapGetters(['bigSum'])


  },
  watch: {},
  filters: {},
  created() {
  },
  mounted() {
  },
  destroyed() {
  },
  methods: {
    // 程序员自己写
    /*increment() {
      this.$store.commit('ADD', this.number)
    },
    decrement() {
      this.$store.commit('DEL', this.number)
    },*/
    /*************************************************/
    // 借助mapMutations生成对应的方法，方法中会调用commit去联系mutations(对象写法)
    ...mapMutations({increment: 'ADD', jian: 'DEL'}),

    /*
    * 相当于创建了一个这样的函数
    * */
    jian(value){
      this.$store.commit('DEL', value)
    },

    decrement() {
      this.jian(this.number)
    },

    // 借助mapMutations生成对应的方法，方法中会调用commit去联系mutations(数组写法)
    // ...mapMutations(['ADD', 'DEL']),
    /***************************************************************************/
    // 程序员自己写
    /*incrementOdd() {
      this.$store.dispatch('addOdd', this.number)
    },
    incrementWait() {
      this.$store.dispatch('addWait', this.number)
    },*/
    /****************************************************************************/
    //借助对象写法
    // ...mapActions({incrementOdd:'addOdd',incrementWait:'addWait'})
    // 数组写过
    ...mapActions(['addOdd','addWait'])

  }
}
</script>

<style scoped>
button {
  margin: 0 10px;
}
</style>